package com.ruoyi.web.controller.cs;

import com.ruoyi.common.core.controller.BasicsController;
import com.ruoyi.common.core.domain.Response;
import com.ruoyi.common.core.page.ResponsePageInfo;
import com.ruoyi.cs.domain.TGoodsPricingRange;
import com.ruoyi.cs.service.TGoodsPricingRangeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName TGoodsPricingRangeController
 * @Description TODO
 * @Author zz
 * @Date 2024/2/5
 **/
@Api(tags = {"饰品价格溢价区间模块"})
@RestController
@RequestMapping("/cs/pricingRanges")
@SuppressWarnings("all")
public class TGoodsPricingRangeController extends BasicsController {
    @Autowired
    private TGoodsPricingRangeService goodsPricingRangeService;

    @GetMapping("/{id}")
    @ApiOperation("详情")
    @PreAuthorize("@ss.hasPermi('cs:pricingRanges:info')")
    public Response<TGoodsPricingRange> getById(@PathVariable Integer id) {
        return Response.success(goodsPricingRangeService.getById(id));
    }

    @GetMapping("/list")
    @ApiOperation("列表")
    @PreAuthorize("@ss.hasPermi('cs:pricingRanges:list')")
    public ResponsePageInfo<TGoodsPricingRange> getAll(@RequestParam("pageNum")Integer pageNum,
                                                       @RequestParam("pageSize") Integer pageSize) {
        startPage(pageNum,pageSize);
        return toResponsePageInfo(goodsPricingRangeService.getAll());
    }

    @PostMapping("/add")
    @ApiOperation("新增")
    @PreAuthorize("@ss.hasPermi('cs:pricingRanges:add')")
    public Response addGoodsPricingRange(@Validated @RequestBody TGoodsPricingRange range) {
        goodsPricingRangeService.addGoodsPricingRange(range);
        return Response.success();
    }

    @PutMapping("/update/{id}")
    @ApiOperation("更新")
    @PreAuthorize("@ss.hasPermi('cs:pricingRanges:update')")
    public Response updateGoodsPricingRange(@PathVariable Integer id,@Validated @RequestBody TGoodsPricingRange range) {
        range.setId(id);
        goodsPricingRangeService.updateGoodsPricingRange(range);
        return Response.success();
    }

    @DeleteMapping("/del/{id}")
    @ApiOperation("删除")
    @PreAuthorize("@ss.hasPermi('cs:pricingRanges:del')")
    public Response deleteById(@PathVariable Integer id) {
        goodsPricingRangeService.deleteById(id);
        return Response.success();
    }
}
